#202题. 快乐数
class Solution:
    def isHappy(self, n: int) -> bool:
        record=set()

        while n not in record:
            record.add(n)

            sum=0
            for i in str(n):
                sum+=int(i)**2

            if sum==1:
                return True
            n=sum

        return False